<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	    		xmlns:ui="http://java.sun.com/jsf/facelets"
	  			xmlns:h="http://java.sun.com/jsf/html"
	  			xmlns:f="http://java.sun.com/jsf/core"
                xmlns:sf="http://www.springframework.org/tags/faces"
                xmlns:cs="http://myfaces.apress.com/custom"
				template="/WEB-INF/layouts/standard.xhtml"
				xmlns:a4j="http://richfaces.org/a4j"
				xmlns:rich="http://richfaces.org/rich"
				xmlns:c="http://java.sun.com/jstl/core">

	<ui:define name="content">	
			<h2>${model}s</h2>
			<h:form id="Building" >
				
				<h:messages errorClass="errors" style="color:#ff1111" />
				
				<fieldset>
					<div class="field">
						<div class="label">Name:</div>
						<c:choose>
							<c:when test="#{editing}">
								<div class="output">
									<h:outputText value="#{building.name}" rendered="#{editing}" />
								</div>									
							</c:when>
							<c:otherwise>
								<div class="input">
									<sf:clientTextValidator required="true">
										<h:inputText required="#{!editing}" rendered="#{!editing}" requiredMessage="Name is required !" id="name" value="#{building.name}">
											<rich:beanValidator/>
											<rich:beanValidator binding="#{nameValidator}" />
										</h:inputText>
									</sf:clientTextValidator>													
								</div>						
							</c:otherwise>	
						</c:choose>												
					</div>
					<div class="field">
						<div class="label">Floors:</div>
						<div class="input">
							<sf:clientTextValidator required="true">
								<h:inputText required="#{!editing}" requiredMessage="Floors is required !" id="floors" value="#{building.floors}">
									<rich:beanValidator summary="Floors must be at least 1"/>
								</h:inputText>
							</sf:clientTextValidator>
						</div>
					</div>
					<div class="buttonGroup">
						<sf:validateAllOnClick>
							<h:commandButton disabled="#{editing}" id="submit" action="add" value="Add"/>&#160;
							<h:commandButton disabled="#{!editing}" action="update" value="Update"/>&#160;
						</sf:validateAllOnClick>
						<h:commandButton id="cancel" immediate="true" value="Cancel" action="cancel"/>
					</div>		
				</fieldset>				
				<rich:dataTable value="${buildings}" var="aBean">
					<rich:column>
						<f:facet name="header">
							<h:outputText value="Edit" />
						</f:facet>
						<h:commandButton disabled="#{editing}" immediate="true" value="Select" action="select"/>
					</rich:column>
					<rich:column>
						<f:facet name="header">
							<h:outputText value="Delete" />
						</f:facet>
						<h:commandButton disabled="#{editing}" immediate="true" value="Delete"  action="delete"
						onclick="if(!showConfirmation('Are you sure to remove building: #{aBean.name} ?')) return false;"/>
					</rich:column>
					<rich:column>
						<f:facet name="header">Name</f:facet>
						<h:outputText value="#{aBean.name}"/>
					</rich:column>
					<rich:column>
						<f:facet name="header">Floors</f:facet>
						<h:outputText value="#{aBean.floors}"/>
					</rich:column>
				</rich:dataTable>
			</h:form>
	</ui:define>
</ui:composition>